<template>
    <div class="layout">
         <div class="yq-main">
            <dl class="yq-tags-types college-types">
                <dd>
                    <dt>
                        <i-button type="text" size="large" v-on:click="getByCatetory(0)">
                            <font :color="categoryId === ''? 'red' : ''" class="all">全部</font>
                        </i-button>
                    </dt>
                    <dt v-for="(category, index) in categoryList" v-bind:key="index">
                        <i-button type="text" size="large" v-on:click="getByCatetory(category.id)">
                            <font :color="categoryId === category.id ? 'red' : ''">{{category.categoryName}}</font>
                        </i-button>
                        <i>|</i>
                    </dt>
                </dd>
            </dl>
            <div class="yq-tags-hot">
                <i-button type="text" size="large" @click="getByOrder('views')">
                    <font :color="orderBy === 'views'? 'red' : ''">最热</font>
                </i-button>
                <i-button type="text" size="large" @click="getByOrder('time')">
                    <font :color="orderBy === 'time'? 'red' : ''">最新</font>
                </i-button>
            </div>
            <div class="clearfix">
                <div class="video-group" v-for="(course, index) in courseList" v-bind:key="index" style="float:left">
                    <div class="video-item">
                        <dt>
                            <img :src="course.poster" alt="" style="height:120px;width:15.5vw;border-radius:10px;">
                            <div class="play-panel"></div>
                            <a class="play-btn" v-on:click="displayCourseDetail(course.id)"></a>
                        </dt>
                        <dd>
                            <h4>
                                <a class="video-title">【{{course.categoryName}}】{{course.topic}}</a>
                            </h4>
                            <div class="v-footer">
                                <span class="lecturer"><Icon type="person" size="20"></Icon>&nbsp;{{course.lecturerName}}</span>
                                <span class="looked"><Icon type="eye" size="15"></Icon>{{course.views}}人浏览</span>
                            </div>
                        </dd>
                    </div>
                </div>
            </div>
        </div>
        <div class="page">
            <Row type="flex" justify="center" class="code-row-bg">
                <Col>
                <Page show-total :total="total" :page-size="pageSize" @on-change="pageCourse"></Page>
                </Col>
            </row>
        </div>
     </div>
</template>
<script>
import axios from 'axios';
import CategoryAPI from '@/api/knowledge/CategoryAPI';
import CourseAPI from '@/api/knowledge/CourseAPI';
export default {
    data() {
        return {
            categoryList: [],
            orderBy: 'views',
            courseList: [],
            categoryId: '',
            pageNum: 1,
            pageSize: 12,
            total: 0,
            maxlength:15,
        }
    },
    mounted() {
        this.fetchParentCategory();
        this.fetchCourseList();
    },
         methods: {
             fetchParentCategory() {
                CategoryAPI.fetchParentCategory((resp)=> {
                     this.categoryList = resp;
                 },(error)=> {
                     this.$Message.error("操作失败【" + error + "】");
                 });
             },
             fetchCourseList() {
                 let _this = this;
                 let params = [_this.categoryId, _this.orderBy, _this.pageNum, _this.pageSize];
                 CourseAPI.fetchCourseList(params, function(resp) {
                     _this.pageNum = resp.pageNum;
                     _this.pageSize = resp.pageSize;
                     _this.total = resp.total
                     _this.courseList = resp.courseList;
                 }, function(error) {
                     _this.$Message.error("操作失败【" + error + "】");
                 });
             },
             displayCourseDetail(courseId) {
                 axios.post(CourseAPI.view_course + '/' + courseId).then(resp => {
                     this.$router.push({ path: "/know-how/course/detail/" + courseId });
                 }).catch(error => {
                     this.$Message.error("操作失败【" + error + "】");
                 });
             },
             getByCatetory(_categoryId) {
                 this.categoryId = _categoryId;
                 if (0 == _categoryId) {
                     this.categoryId = '';
                 }
                 this.fetchCourseList();
             },
             getByOrder(_order) {
                 this.orderBy = _order;
                 this.fetchCourseList();
             },
             pageCourse(current) {
                 this.pageNum = current;
                 this.fetchCourseList();
             }
         }
}
</script>
<style scoped>
html,body{
  background-color: #fff;
}
 .layout {
    width: 100vw;
    height: 100vh;
    position: relative;
    margin: 0 auto;
    overflow: hidden;
    margin-bottom: 50px;
    background-color:#fff;
}
.yq-main {
    width: 70vw;
    position: relative;
    margin: 0 auto;
}

.code-row-bg{
    margin-top: 20px;
    width: 70vw;
}

.college-types {
    border: 0!important;
    border-bottom: 1px dashed #c8c8c8!important;
    padding: 20px 0;
}

 .college-types:after {
    content: "";
    display: block;
    clear: both;
}

.college-types:nth-of-type(n+2) {
    margin-top: 0!important;
}

.college-types dt {
    min-width: 71px;
    height: 35px;
    text-align: center;
    line-height: 33px!important;
    display: inline-block;
    margin-top: 10px;
    background-color: #f0f0f0;
    margin-top:60px;
}

.college-types dd {
    float: left;
    line-height: 26px;
    position: relative;
}

.video-group {
    width: 15.5vw;
    height: auto;
    margin-bottom: 10px;
    margin-right: 25px;
    padding-left: -40px;
    border-radius: 10px;
    border: 1px solid #e4e4e4;
}

.video-group .video-item {
    background: #f9f9f9;
    height: 13%;
    margin: 0 20px;
    margin-bottom: 20px;
}
.video-group .video-item .info-text {
    line-height: 224px;
    display: inline-block;
    width: 100%;
    text-align: center;
    color: #999
}

.video-group .video-item:nth-child(4n) {
    margin-right: 0
}

 .yq-tags-hot {
    border-bottom: 1px dashed #c8c8c8!important;
    padding: 5px 0;
    margin: 0 0 20px 0;
}

.video-group .video-item dt {
    position: relative;
    height: 156px;
    width: auto;
    margin-left: -20px;
}

.video-group .video-item dt .play-panel {
    left: 0;
    top: 0;
    width: 15.5vw;
    height:120px;
    margin-right: 50px;
    overflow: hidden;
    position: absolute;
    background: transparent;
    -webkit-transition: all 0.45s;
    transition: all 0.45s
}

.video-group .video-item dt .play-btn {
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -50px;
    margin-left: -17px;
    height: 55px;
    width: 55px;
    background: url(../../assets/play_btn.png);
    background-size: 55px 55px;
    -webkit-transition: all 0.45s;
    transition: all 0.45s;
    opacity: 0;
    filter: alpha(opacity=0);
    -ms-filter: progid:DXImageTransform.Microsoft.Alpha(opacity=(0))
}

.video-group .video-item dt .play-btn.icon-play-btn {
    background: none;
    height: 55px;
    width: 55px;
    font-size: 55px;
    color: #fff;
    text-decoration: none
}
.video-group .video-item:hover .play-panel {
    background: rgba(0, 0, 0, .5);
    border-radius: 10px;
    overflow: hidden;
}

.video-group .video-item:hover .play-btn {
    opacity: 1;
    filter: alpha(opacity=100);
    -ms-filter: progid:DXImageTransform.Microsoft.Alpha(opacity=(100))
}

.video-group .video-item dd {
    width: 15.5vw;
    margin-top: -30px;
    margin-left: -20px;
}
.video-group .video-item dd h4 .video-title {
    width: 200px;
    display: inline-block;
    font-size: 12px;
    line-height: 24px;
    color: #333;
    overflow: hidden; 
    text-overflow:ellipsis;
    white-space: nowrap;
    padding-left: -10px;
}

.video-group .video-item dd h4 .video-time {
    float: right;
    display: none;
    color: #666;
    font-size: 14px;
    line-height: 24px;
}

.video-group .video-item dd .v-footer {
    color: #999;
    margin-top: 10px;
}

.video-group .video-item dd .v-footer .lecturer i {
    height: 14px;
    width: 5px;
    display: inline-block;
    background: url(../../assets/play_btn.png);
    margin-right: 10px;
    padding: 0px 10px 0px 10px;
    vertical-align: -3px
}

.video-group .video-item dd .v-footer .lecturer i.icon-video-mac {
    background: none;
    vertical-align: middle;
    margin-right: 10px
}

.video-group .video-item dd .v-footer .looked {
    float: right;
    padding-right: 10px;
}

.video-group .video-item dd .v-footer .looked i {
    height: 12px;
    width: 16px;
    display: inline-block;
    background: url(../../assets/play_btn.png);
    margin-right: 10px;
    vertical-align: -2px
}

.video-group .video-item dd .v-footer .looked i.icon-watched {
    background: none;
    vertical-align: middle;
    margin-right: 3px
}

/* 底部分页 */
.page{
    width: 70vw;
    height: 100px;
    margin: 0 auto;
}
</style>
